<?php


namespace app\lunwen\controller;


use app\lunwen\model\DepartmentUploadFileModel;


use app\lunwen\model\EducationalUploadFileModel;
use app\lunwen\model\TeacherUploadFileModel;
use cmf\controller\HomeBaseController;

class EducationalFileOperateController extends HomeBaseController
{
    public function downFile(){
        //查出状态为院系已提交的文件
        $file = new DepartmentUploadFileModel();
        $data = $file->where('status','in','院系已提交,管理人员通过,管理人员不通过')
            ->whereTime('create_time','>',session('beforeYear'))
            ->whereTime('create_time','<',session('afterYear'))
            ->all();
        $this->assign('file',$data);
        return $this->fetch(':educationalDownFile');
    }

    public function passWord(){
        //改状态为教秘通过 返回一个成功
        $teacherFile = new TeacherUploadFileModel();
        $teacherFile->where("file_name",$_GET["fileName"])
            ->update(['status' =>'管理人员通过']);

        $DepartmentFile = new DepartmentUploadFileModel();
        $DepartmentFile->where("file_name",$_GET["fileName"])
            ->update(['status' =>'管理人员通过']);
        echo "<script>alert('成功！')</script>";

        $file = new TeacherUploadFileModel();
        $data = $file
            ->whereTime('create_time','>',session('beforeYear'))
            ->whereTime('create_time','<',session('afterYear'))
            ->all();
        $this->assign('file',$data);
        return $this->fetch(':educationalDownFile');
    }

    public function notPassWord(){
        //改状态为院系不通过
        //改状态为院系通过 返回一个成功
        $teacherFile = new TeacherUploadFileModel();
        $teacherFile->where("file_name",$_GET["fileName"])
            ->update(['status' =>'管理人员不通过']);
        echo "<script>alert('成功！')</script>";

        $file = new TeacherUploadFileModel();
        $data = $file
            ->whereTime('create_time','>',session('beforeYear'))
            ->whereTime('create_time','<',session('afterYear'))
            ->all();
        $this->assign('file',$data);
        return $this->fetch(':educationalDownFile');
    }

    public function downButton(){

        $data = "D:\phpstudy_pro\\thinkcmf\ThinkCMF\public\static\\departmentFile\\{$_GET["file_name"]}";
        echo $filename = $_GET["file_name"];
        return \download($data,$_GET["file_name"],false);

    }

    public function uploadFile(){
        $file = new EducationalUploadFileModel();
        $data = $file
            ->whereTime('create_time','>',session('beforeYear'))
            ->whereTime('create_time','<',session('afterYear'))
            ->all();
        $this->assign('title',$data);
        return $this->fetch(':educationalUpload');
    }

    public function delete(){
        //echo $_GET["stu_id"];
        //echo $_GET["file_name"];
        //删除文件
        echo $filename = "D:\phpstudy_pro\\thinkcmf\ThinkCMF\public\static\\educationalFile\\{$_GET["file_name"]}";
        unlink($filename);

        //删除数据库
        $del = new EducationalUploadFileModel();
        $del->where('stu_id',$_GET["stu_id"])
            ->where('file_name',$_GET["file_name"])
            ->delete();

        $file = new EducationalUploadFileModel();
        $data = $file
            ->whereTime('create_time','>',session('beforeYear'))
            ->whereTime('create_time','<',session('afterYear'))
            ->all();
        $this->assign('title',$data);
        return $this->fetch(':educationalUpload');
    }
}